package org.tgcms.core.samples.contentcreator;

import java.util.Arrays;
import java.util.List;

import org.tgcms.core.dal.dao.DaoException;
import org.tgcms.core.dal.dao.PageDao;
import org.tgcms.core.dal.dao.TemplateDao;
import org.tgcms.core.dal.dao.WebsiteDao;
import org.tgcms.core.dal.dto.Attachment;
import org.tgcms.core.dal.dto.Page;
import org.tgcms.core.dal.dto.Template;
import org.tgcms.core.dal.dto.Website;
import org.tgcms.core.samples.contentcreator.domain.SampleAttachment;
import org.tgcms.core.samples.contentcreator.domain.SamplePage;
import org.tgcms.core.samples.contentcreator.domain.SampleTemplate;
import org.tgcms.core.samples.contentcreator.domain.SampleWebsite;

public class ContentCreator {
	
	WebsiteDao websiteDao;
	TemplateDao templateDao;
	PageDao pageDao;
	
	public ContentCreator(WebsiteDao websiteDao, TemplateDao templateDao,
			PageDao pageDao) {
		this.websiteDao = websiteDao;
		this.templateDao = templateDao;
		this.pageDao = pageDao;
	}
	
	public void createSampleContent() throws DaoException {
		Website website = new SampleWebsite();
		website.setName("Default website");
		website.setUrls(Arrays.asList("localhost"));
		website = websiteDao.put(website);
		
		Template template = new SampleTemplate();
		template.setName("Default template");
		template.setContentType("text/html; charset=utf-8");
		template.setHtml("sample html");
		template = templateDao.put(template);
		
		Page rootPage = new SamplePage();
		rootPage.setTitle("Root page");
		rootPage.setContent("sample content");
		rootPage.setUrl("index.html");
		rootPage.setTemplate(template);
		Attachment a = new SampleAttachment();
		a.setTitle("sample a");
		rootPage.getAttachments().add(a);
		
		rootPage = pageDao.put(rootPage);
		
		template.setName("qwe");
		rootPage.setTitle("qwe");
		rootPage.getAttachments().get(0).setTitle("qwe1");
		pageDao.put(rootPage);
		
		List<Page> list = pageDao.listAll();
		System.out.println("t: "+list.get(0).getTitle());
		list.get(0).setTitle("ttt");
		System.out.println("t: "+list.get(0).getAttachments().get(0).getTitle());
		list.get(0).getAttachments().get(0).setTitle("sss");
		pageDao.put(list.get(0));
		
	}
	
}
